﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Bootstrap5.Abstractions;

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;

namespace Bootstrap5;

[CssClass("btn-check")]
public class FormInputRadioButton<TValue>:FormInputRadio<TValue>
{
    [Parameter] public bool Outline { get; set; }
    [Parameter] public Color Color { get; set; } = Color.Primary;
    protected override void BuildRenderTree(RenderTreeBuilder builder)
    {
        BuildInput(builder);
        BuildLabel(builder);
    }
    protected override void BuildLabel(RenderTreeBuilder builder)
    {
        builder.OpenElement(0, "label");
        builder.AddAttribute(1, "for", Id);
        builder.AddAttribute(2, "class", GetCheckButtonLabelClass());
        builder.AddContent(10, Text);
        builder.CloseElement();
    }

    string GetCheckButtonLabelClass()
    {
        var list = new List<string>() { "btn" };

        list.Add($"btn-{(Outline ? "outline-" : null)}{Color.GetEnumCssClass()}");
        return string.Join(" ", list);
    }
}
